package com.example.spinning.service;

import com.example.spinning.bean.DailyReport;
import com.example.spinning.bean.MonthlyReport;
import com.example.spinning.mapper.MonthlyReportMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Date;
import java.util.List;


@Service
@Transactional
public class MonthlyReportService {
    @Autowired
    MonthlyReportMapper monthlyReportMapper;

    //增加操作
    public int addNewMonthlyReport(MonthlyReport monthlyReport) {
       //monthlyReport.setDate(new Timestamp(System.currentTimeMillis()));
        return monthlyReportMapper.addNewMonthlyReport(monthlyReport);
    }

    //删除操作
    public boolean deleteMonthlyReportById(Long[] ids) {
        int result = monthlyReportMapper.deleteMonthlyReportById(ids);
        return result == ids.length;
    }

    //查询并分页
    public PageInfo<MonthlyReport> findPage(Integer page, Integer size,String workshop,String month) {

        MonthlyReport monthlyReport = new MonthlyReport();
        monthlyReport.setWorkshop(workshop);
        monthlyReport.setMonth(month);

        PageHelper.startPage(page,size);
        List<MonthlyReport> list = monthlyReportMapper.select(monthlyReport);
        PageInfo<MonthlyReport> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }
    //动态修改
    public int updateCategoryById(MonthlyReport monthlyReport){
        int result = monthlyReportMapper.updateByPrimaryKeySelective(monthlyReport);
        return result;
    }

}




